class BlogsController < ApplicationController
    def index
        if !signed_in?
            deny_access
        end
        @blogs = Blog.all
    end

    def new
    end

    def show
        @blog = Blog.find(params[:id])
        @posts = @blog.posts.order("created_at desc")
    end

    def create
        @blog = Blog.new(params[:blog].permit(:name, :description))
        if @blog.save
            current_user.blogs.push(@blog)
            redirect_to blogs_path
        else
            render 'new'
        end
    end

    def destroy
        @blog = Blog.find(params[:id])
        @blog.destroy
        redirect_to blogs_path
    end
end
